﻿using Iot.Models;
using Microsoft.AspNetCore.Mvc;

namespace Iot.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class HomeController : ControllerBase
    {
        private readonly IClientWorker? _clientWorker;

        public HomeController(IClientWorker? clientWorker)
        {
            _clientWorker = clientWorker;
        }

        public async Task<string> GetAsync(string mac,string status, int gpio)
        {
            await _clientWorker?.PublishAsync(MQTTTOPIC.CONTROL, new MQTTMessage() { Msg = status, To = mac, GPIO = gpio })!;
            await _clientWorker?.PublishAsync(MQTTTOPIC.CONTROL, new MQTTMessage() { Msg = "2", To = mac, GPIO = gpio })!;

            return $"{mac}-{gpio}-{status} OK";
        }
    }
}
